// hdu5937
// 题意：
// 题解：
//
// ml:run = $bin < input
// ml:opt = 0
// ml:ccf += -g
#include <iostream>
#include <cstring>
#include <vector>

/* int const limit[] = {0, 16, 15, 14, 13, 12, 11, 10, 9, 8}; */

struct equ { int x, y, z; };
std::vector<equ> const equation{
                                    {2, 3, 5}, {2, 4, 6}, {2, 5, 7}, {2, 6, 8}, {2, 7, 9},
                                    {3, 4, 7}, {3, 5, 8}, {3, 6, 9},
                                    {4, 5, 9},
                               };
int const maxn = 12;
int pow3[maxn];
int count[maxn];
int back[maxn];
int a[maxn];
int tmp, ttmp, ans;

void add(int x, int y, int z)
{
    count[x]++; count[y]++; count[z]++;
    tmp++;
}

void backup()
{
    ttmp = tmp;
    for (int i = 0; i < maxn; i++) back[i] = count[i];
}

void restore()
{
    tmp = ttmp;
    for (int i = 0; i < maxn; i++) count[i] = back[i];
}

bool greater()
{
    for (int i = 1; i <= 9; i++)
        if (count[i] > a[i]) return true;
    return false;
}

void init()
{
    pow3[0] = 1;
    for (int i = 1; i < maxn; i++)
        pow3[i] = pow3[i - 1] * 3;
}

void greedy()
{
    for (int i = 0; i < maxn; i++) count[i] = a[i] - count[i];
    for (int i = 8; i >= 2; i--) {
        if (count[1] == 0) return;
        if (count[i] && count[1] && count[i + 1]) {
            tmp++;
            count[i]--; count[1]--; count[i + 1]--;
        }
        if (count[i] && count[1] && count[i + 1]) {
            tmp++;
            count[i]--; count[1]--; count[i + 1]--;
        }
    }
    if (count[1] >= 2 && count[2]) tmp++;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    init();
    int T; std::cin >> T;
    for (int ti = 1; ti <= T; ti++) {
        std::cout << "Case #" << ti << ": ";
        for (int i = 1; i <= 9; i++) std::cin >> a[i];
        ans = 0;
        // iterator for x + x = 2 * x, 2 <= x <= 4
        for (int i = 0; i < (1 << 3); i++) {
            memset(count, 0, sizeof(count));
            tmp = 0;
            for (int j = 0; j < 3; j++)
                if ((i >> j) & 1) add(j + 2, j + 2, 2 * (j + 2));
            if (greater()) continue;

            for (int j = 0; j < pow3[9]; j++) {
                backup();

                if (j == 18) {
                    j = 18;
                }
                for (int t = 0, ts = j; t < 9; t++, ts /= 3) {
                    if (ts % 3 == 0) continue;
                    add(equation[t].x, equation[t].y, equation[t].z);
                    if (ts % 3 == 2) add(equation[t].x, equation[t].y, equation[t].z);
                }

                if (greater()) {
                    restore();
                    continue;
                }

                greedy();
                ans = std::max(ans, tmp);
                restore();
            }
        }
        std::cout << ans << "\n";
    }
}

